import Vue from 'vue'
import Vuex from 'vuex'
import {loginDetail, logOutLogin, peopleMessage} from "../api/api";
import cart from "./modules/cart";
import { message , notification } from 'ant-design-vue'
Vuex.Store.prototype.$notification = notification;
Vuex.Store.prototype.$message = message;
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        showHide: false,
        regisState: false,
        changColorLove: true,
        logAfter: false,
        //个人信息数组
        userContent:[]
    },
    mutations: {
        //弹出模态框 注册登录的
        changeFT(state, mm) {
            state.showHide = mm
        },
        //爱心收藏状态
        changLove(state, love) {
            state.changColorLove = love
        },
        // 注册模态框
        registerFT(state, register) {
            state.regisState = register
        },
        //    改变登录状态
        changeLogin(state, headChange) {
            state.logAfter = headChange
        },
        //登录用户个人信息
        userContent(state,user){
            state.userContent=user
        }
    },
    actions: {
        isLogin(context,payload) {
            loginDetail(payload.userName, payload.password).then(res => {
                console.log(res);
                //登陆后的用户信息存到一个数组里
                context.commit("userContent",res.userInfo)
                console.log(this.state.userContent)
                if(res.code!=500){
                    context.commit("changeLogin",true);
                    context.commit("changeFT",false);
                    this.$message.success("登录成功")
                }else{
                    context.commit("changeFT",true);
                    this.$message.error("登录失败")
                }
            })
        },
        logout(context){
            logOutLogin().then(res=>{
                console.log(res)
                context.commit("changeLogin",false);




            })
        },
        getMessage(context){
            peopleMessage().then(res=>{
                console.log(res)
                context.commit("changeLogin",true);
                context.commit("userContent",res.userInfo)
            })
        }


    },
    modules: {
        cart
    }
})
